/*
ID:luongho3
LANG:C++
TASK:agrinet
*/
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin("agrinet.in");
ofstream fout("agrinet.out");
#define N_FARM 200
#define INF 2000000000
int nFarm,totalWeight;
int m[N_FARM][N_FARM], label[N_FARM], occupied[N_FARM];
int main() {
    fin >> nFarm;
    int i,j;
    for (i=1;i<=nFarm;++i) {
        for (j=1;j<=nFarm;++j) {
            fin >> m[i][j];
        }
        label[i] = INF;
        occupied[i] = 0;
    }
    totalWeight = 0;
    label[1] = 0;
    int minVal, key;
    for (i=1;i<=nFarm;++i) {
        minVal = INF;
        key = -1;
        for (j=1;j<=nFarm;++j) {
            if (label[j] < minVal && occupied[j] == 0) {
               minVal = label[j];
               key = j;
            }
        }
        if (key == -1) {
           break;
        }
        occupied[key] = 1;
        totalWeight += label[key];
        for (j=1;j<=nFarm;++j) {
            if (j!=key && label[j] > m[key][j]) {
               label[j] = m[key][j];
            }
        }
    }
    fout << totalWeight << "\n";
    return 0;
}
